#define content_plugin()
<div class="box box-warning box-jianshu">
    <div class="box-header with-border">
        <h3 class="box-title">插件设置</h3>
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <!-- 两步验证 - Slug -->
        <div class="col-xs-12">
            <div class="form-group">
                <label>两步验证#(ssaEnable ? "<span style='color:green'>已开启</span>" : "<span style='color:red'>未开启</span>")</label>
                #if(ssaEnable)
                <p><button id="ssaDisable" class="btn btn-default" onclick="showSsaConfig(false)">关闭</button></p>
                #else
                <p><button id="ssaEnable" class="btn btn-warning" onclick="showSsaConfig(true)">开启两步验证</button></p>
                #end
            </div>
        </div>
        <!-- /.box-body -->
    </div>
</div>
<script>
    function showSsaConfig(enable){
        $.showLoading();
        // 关闭验证
        if(!enable){
            $.prompt({
                title: '确定关闭？',
                text: '关闭两步验证会增加账号风险',
                input: '输入验证码',
                empty: false, // 是否允许为空
                onOK: function (input) {
                    //点击确认
                    setSsaConfig(false, "", input);
                },
                onCancel: function () {
                    //点击取消
                    $.hideLoading();
                }
            });
            return;
        }

        // 开启验证
        ajaxPost('#(CAPTH)/admin/articlesync/ssa/ssaRndCode', {

        },  function (result) {
            $.hideLoading();
            var key = result.ssaObj.ssaKey;
            var qrCode = result.ssaObj.qrCode;
            $.prompt({
                title: '谷歌验证器扫码添加',
                text:
                    '<p><div id="ssaQrCode"></div></p>' +
                    '<p><small>' + key + '</small></p>',
                input: '输入验证器中的数值',
                empty: false, // 是否允许为空
                onOK: function (input) {
                    //点击确认
                    setSsaConfig(enable, key, input)
                },
                onCancel: function () {
                    //点击取消
                }
            });
            setTimeout($("#ssaQrCode").qrcode({
                width:200,
                height:200,
                text:qrCode
            }), 200);
        },  function (result) {
            $.hideLoading();
            showErrorMessage(result.message);
            setTimeout(document.location.reload(), 1000);
        })
    }

    function setSsaConfig(enable, key, code){
        return ajaxPost('#(CAPTH)/admin/articlesync/ssa/doSetSSAuth', {
            enable : enable,
            key : key,
            code :code
        },  function (result) {
            showMessage(result.message);
            setTimeout(document.location.reload(), 500);
        },  function (result) {
            showErrorMessage(result.message);
            return false;
        })
    }
</script>
#end
